#include "dictionary.h"
#include "ebook.h"
#include "../utils/fileutils.h"
#include <fstream>

using namespace std;

Dictionary::Dictionary(const char* dictionaryPath)
{
    readDictionary(dictionaryPath);
}

void Dictionary::readDictionary(const char* path) throw (FileException)
{
    if(!path)
        throw NullPathException();
    if(!exist(path))
        throw FileNotFoundExpcetion(path);
    
    ifstream file(path);
    
    if(!file.is_open())
        throw OpenFileException(path);
    
    string buffer;
    
    while(getline(file, buffer))
    {
        trimLine(buffer);
        words.push_back(buffer);
    }
    file.close();
}
